import com.zdy.pojo.Books;
import com.zdy.service.BookServiceImpl;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * Created by 逸足天涯
 * on 3/13/2020.
 */
public class Mytest {


    @Test
    public void queryAll(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookServiceImpl bookServiceImpl = (BookServiceImpl) context.getBean("bookServiceImpl");
        List<Books> books = bookServiceImpl.queryAllBooks();
        books.forEach((book)-> System.out.println(book));
    }

    @Test
    public void addBookTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookServiceImpl bookServiceImpl = (BookServiceImpl) context.getBean("bookServiceImpl");
        Books book = new Books("乖，摸摸头",6,"文学作品");
        int row = bookServiceImpl.addbook(book);
        System.out.println("插入"+row+ "条数据");

    }

    @Test
    public void deleteBookTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookServiceImpl bookServiceImpl = (BookServiceImpl) context.getBean("bookServiceImpl");

        int row = bookServiceImpl.deleteBookById(7);
        System.out.println("删除"+row+ "条数据");

    }

    @Test
    public void updateBookTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookServiceImpl bookServiceImpl = (BookServiceImpl) context.getBean("bookServiceImpl");
        Books book = new Books(4,"乖，摸摸头",80,"文学作品");
        int row = bookServiceImpl.updateBooks(book);
        System.out.println("修改"+row+ "条数据");

    }

    @Test
    public void queryOneBookTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookServiceImpl bookServiceImpl = (BookServiceImpl) context.getBean("bookServiceImpl");
        Books books = bookServiceImpl.queryOneBookById(2);
        System.out.println(books);

    }

    @Test
    public void queryBookByNameTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookServiceImpl bookServiceImpl = (BookServiceImpl) context.getBean("bookServiceImpl");
        Books books = bookServiceImpl.queryBookByName("Linux");
        System.out.println(books);

    }

}
